package com.oracle.zebrafreelytraveling.ui.adapter;

import com.facebook.drawee.view.SimpleDraweeView;
import com.oracle.zebrafreelytraveling.R;
import com.oracle.zebrafreelytraveling.data.bean.User;
import com.oracle.zebrafreelytraveling.data.model.Message;
import com.oracle.zebrafreelytraveling.ui.BaseRecycleAdapter.base.ItemViewDelegate;
import com.oracle.zebrafreelytraveling.ui.BaseRecycleAdapter.base.ViewHolder;
import com.oracle.zebrafreelytraveling.utils.constant.Constant;
import com.oracle.zebrafreelytraveling.utils.UserUtil;

/**
 * Created by yydcnjjw on 2017/7/27.
 * 接收消息adapter
 */

public class MsgSendItemDelagate implements ItemViewDelegate<Message> {

    @Override
    public int getItemViewLayoutId() {
        return R.layout.item_chat_send;
    }

    @Override
    public boolean isForViewType(Message item, int position) {
        if (item.getType() == Constant.TYPE_SEND){
            return true;
        } else {
            return false;
        }
    }

    @Override
    public void convert(ViewHolder holder, Message message, int position) {
        holder.setText(R.id.msg_left, message.getContent());
        SimpleDraweeView userHeadImg = holder.getView(R.id.chat_user_head);
        User userLocal = UserUtil.getUserInfoLocalBySP();
        User userNet = UserUtil.getUserInfoFromSP();
        if (userLocal.getHeadImg()!=null){
            userHeadImg.setImageURI(userLocal.getHeadImg());
        } else {
            userHeadImg.setImageURI(Constant.DOWNLOAD_URL + userNet.getHeadImg());
        }
        holder.setText(R.id.chat_user_name, userLocal.getName());

    }
}
